package fr.pud.client.controller.query;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;

import fr.pud.client.i18n.LanguagesConstants;
import fr.pud.client.images.ImagesDatabase;
import fr.pud.client.view.MapQueries;

/**
 * Apr 13, 2012 - Projet_Ose.
 * @author Simon Devineau, Adrien Hierry, Leopold Houdin, Pierre Reliquet
 *         Ecole des Mines de Nantes
 *         DisplayOrHideQueries.java
 *         This class allows to the user to display or hide the queries.
 */
public class DisplayOrHideQueries extends AbstractAction {
    private static final long serialVersionUID = -8591776895774317352L;

    /**
     * The default constructor
     */
    public DisplayOrHideQueries() {
        this.putValue(NAME, LanguagesConstants.LANGUAGE
                .getString(LanguagesConstants.HIDE_THE_QUERIES));
        this.putValue(
                SHORT_DESCRIPTION,
                LanguagesConstants.LANGUAGE
                        .getString(LanguagesConstants.DISPLAY_THE_QUERIES)
                        + " "
                        + LanguagesConstants.LANGUAGE
                                .getString(LanguagesConstants.OR)
                        + " "
                        + LanguagesConstants.LANGUAGE
                                .getString(LanguagesConstants.HIDE_THE_QUERIES));
        this.putValue(SMALL_ICON, ImagesDatabase.HIDE_QUERIES);
    }

    /*
     * (non-Javadoc)
     * @see
     * java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
     */
    @Override
    public void actionPerformed(ActionEvent aArg0) {
        if (MapQueries.getInstance().isMapQueriesVisible()) {
            this.putValue(NAME, LanguagesConstants.LANGUAGE
                    .getString(LanguagesConstants.DISPLAY_THE_QUERIES));
            this.putValue(SMALL_ICON, ImagesDatabase.ROAD);
            MapQueries.getInstance().setMapQueriesVisible(false);
        }
        else {
            this.putValue(NAME, LanguagesConstants.LANGUAGE
                    .getString(LanguagesConstants.HIDE_THE_QUERIES));
            this.putValue(SMALL_ICON, ImagesDatabase.HIDE_QUERIES);
            MapQueries.getInstance().setMapQueriesVisible(true);
        }
    }
}
